Skip to content

Remove useless flag reset before execution#73

Merged
maxlandon merged 2 commits intomainfrom
dev
Jul 10, 2025
Merged

Remove useless flag reset before execution#73
maxlandon merged 2 commits intomainfrom
dev

Conversation

@maxlandon
Copy link
Member

No description provided.

@maxlandon maxlandon merged commit 4d38cb4 into main Jul 10, 2025
7 checks passed
@btwotch
Copy link

btwotch commented Sep 2, 2025

@maxlandon Why is this useless? F.e. it breaks the following code:

func main() {
	app := console.New("TestApp")

	menu := app.ActiveMenu()
	menu.AddInterrupt(io.EOF, func(c *console.Console) {
		os.Exit(0)
	})

	rootCmd := &cobra.Command{
		Args: cobra.ExactArgs(0),
	}
	fooCmd := &cobra.Command{
		Use:  "foo",
		Args: cobra.ExactArgs(0),
		Run: func(cmd *cobra.Command, args []string) {
			// debug.PrintStack()
			fmt.Printf(">>> foo\n")
		},
	}

	f := func() *cobra.Command {
		rootCmd.AddCommand(fooCmd)
		return rootCmd
	}

	menu.SetCommands(f)

	app.Start()
}

if you run:

foo --help

and then

foo

then the second run will not succeed

@maxlandon
Copy link
Member Author

Hello,

This is indeed a regression I failed to notice when merging my changes.

Will be fixed in the coming days.

@btwotch
Copy link

btwotch commented Sep 5, 2025

Hello,

This is indeed a regression I failed to notice when merging my changes.

Will be fixed in the coming days.

Cool! Thank you very much.

Btw. I saw there is also https://pkg.go.dev/github.com/spf13/cobra#Command.ResetFlags but I did not check the differences between your implementation and it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants